#!/usr/bin/python3
# coding:utf-8


'''
    class python进度条
    1、function init
    参数：
    1、父窗口 master
    2、起始坐标 x, y
    3、宽高 width, height

    2、function set_fmt
    1、背景色 bg
    2、前景色 fg
    3、边框大小 frame_size
    4、文字位置 n上,s下,W左, e右

    3、function run
    参数：
    1、百分比 percentage
    2、显示的文字 text
'''

from tkinter import *

pb_x = 0
pb_y = 0
pb_width = 200
pb_height = 20

pb_bg = "white"
pb_fg = "green"
pb_frame_size = 0
canvas = Canvas



class progress:
    def __init__(self):
        pass

    # 初始化，创建Canvas实例，设定坐标和宽高
    def init(self, master, x=pb_x, y=pb_y,
             width=pb_width, height=pb_height,
             bg=pb_bg, fg=pb_fg,
             frame_size=pb_frame_size):
        global pb_x
        pb_x = x

        global pb_y
        pb_y = y

        global pb_width
        pb_width = width

        global pb_height
        pb_height = height

        global pb_bg
        pb_bg = bg

        global pb_fg
        pb_fg = fg

        global pb_frame_size
        pb_frame_size = frame_size

        global canvas
        canvas = Canvas(master, width=width, height=height, bg=pb_bg)
        canvas.place(x=x, y=y)
        self.fill_line = canvas.create_rectangle(0, 0, 200, 200, width=0, fill=pb_fg)
        
    # 运行进度条
    def run(self, master, percentage):
        global canvas
        # fill_line = canvas.create_rectangle(0, 0, 200, 200, width=0, fill=pb_fg)
        canvas.coords(self.fill_line, (0, 0, percentage, 100))
        
        master.update()

    